import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/index/Login'
import MainIndex from '@/components/MainIndex'
import Waits from '@/components/messages/Waits'
import Emails from '@/components/messages/Emails'
import People from '@/components/messages/People'
import Waitwatch from '@/components/messages/Waitwatch'
import Reads from '@/components/messages/Reads'
import Personnel from '@/components/messages/Personnel'
import Talk from '@/components/messages/Talk'
import Communtcation from '@/components/addresslist/Communtcation'
import PublicTel from '@/components/addresslist/PublicTel'
import TelFunction from '@/components/addresslist/TelFunction'
import TelDetail from '@/components/addresslist/TelDetail'
import Work from '@/components/works/Work'
import Notes from '@/components/works/children/Notes'
import NoteTree from '@/components/works/children/NoteTree'
import NoteDetail from '@/components/works/children/NoteDetail'
import Editors from '@/components/works/children/Editors'
import UserMain from '@/components/usermain/UserMain'
import TextChange from '@/components/works/children/children/TextChange'
import Learn from '@/components/knowledge/Learn'

Vue.use(Router)

const router = new Router({
	mode: 'hash',
	routes: [
		{path: '/', component: login},
		{path: '/login', component: login},
		{path: '/MainIndex', component: MainIndex},
		{path: '/Waits', component: Waits},
		{path: '/Emails', component: Emails},
		{path: '/People', component: People},
		{path: '/Waitwatch', component: Waitwatch},
		{path: '/Reads', component: Reads},
		{path: '/Personnel', component: Personnel},
		{path: '/Talk', component: Talk},
		{path: '/Communtcation', component: Communtcation},
		{path: '/PublicTel', component: PublicTel},
		{path: '/TelFunction', component: TelFunction},
		{path: '/TelDetail', component: TelDetail},
		{path: '/Work',component: Work},
		{path: '/Notes',component:Notes},
		{path: '/NoteTree',component:NoteTree},
		{path: '/NoteDetail',component:NoteDetail},
		{path: '/Editors',component:Editors},
		{path: '/TextChange',component:TextChange},
		{path: '/Learn', component: Learn},
		{path: '/UserMain', component: UserMain},
	]
});
//路由守卫
router.beforeEach(function(to, from, next){
	var token = localStorage.getItem("appUserToken");
	if (to.path == '/login' || to.path == '/') {
		if(token == '' || token == null || token == 'undefined'){
			localStorage.setItem("appUserToken", "");
			next();
		}else{
			next({path: '/MainIndex'});
		}
	} else{
		//是否在登录状态下
		if(token == '' || token == null || token == 'undefined'){
			next({path: '/login'});
		}else{
			next();
		}
	}
});
export default router;